package com.bioroadlab.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;

import com.bioroadlab.service.DiseaseCategoryService;
import com.bioroadlab.service.DiseaseKeywordService;
import com.bioroadlab.service.DiseaseService;
import com.bioroadlab.service.DiseaseTypeService;
import com.bioroadlab.service.PatientService;
import com.bioroadlab.service.RegistedService;
import com.bioroadlab.service.SampleInfoService;
import com.bioroadlab.service.SysuserService;
import com.bioroadlab.service.TestItemService;
import com.bioroadlab.service.TestObjectService;
import com.bioroadlab.service.TestStatusService;
import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;

public abstract class BaseAction extends ActionSupport implements SessionAware {

	private static final long serialVersionUID = 1L;

	public static final String LIST = "list";

	private Map<String, Object> session;

	private DiseaseService diseaseService;
	private DiseaseTypeService diseaseTypeService;
	private DiseaseKeywordService diseaseKeywordService;
	private TestItemService testItemService;
	private TestObjectService testObjectService;
	private DiseaseCategoryService diseaseCategoryService;
	private SysuserService sysuserService;
	private PatientService patientService;
	private SampleInfoService sampleInfoService;
	private TestStatusService testStatusService;
	private RegistedService registedService;

	@Override
	public abstract String execute() throws Exception;
	
	
	public void sendForTrue(){
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/json;charset=utf-8");
			PrintWriter out = response.getWriter();
			out.print("true".toString());
			out.flush();
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void sendForFalse(){
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/json;charset=utf-8");
			PrintWriter out = response.getWriter();
			out.print("false".toString());
			out.flush();
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void sendJson(Object o) {
		
		Gson gson = new Gson();
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json;charset=utf-8");
		try {
			PrintWriter out = response.getWriter();
			out.print(gson.toJson(o));
			out.flush();
			out.close();
		} catch (IOException e) {

			e.printStackTrace();
		}
	}

	public void putInSession(String key, Object value) {
		session.put(key, value);
	}

	public Object getFromSession(String key) {
		return session.get(key);
	}

	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;
	}

	public DiseaseService getDiseaseService() {
		return diseaseService;
	}

	@Autowired
	public void setDiseaseService(DiseaseService diseaseService) {
		this.diseaseService = diseaseService;
	}

	public DiseaseTypeService getDiseaseTypeService() {
		return diseaseTypeService;
	}

	@Autowired
	public void setDiseaseTypeService(DiseaseTypeService diseaseTypeService) {
		this.diseaseTypeService = diseaseTypeService;
	}

	public TestItemService getTestItemService() {
		return testItemService;
	}

	@Autowired
	public void setTestItemService(TestItemService testItemService) {
		this.testItemService = testItemService;
	}

	public TestObjectService getTestObjectService() {
		return testObjectService;
	}

	@Autowired
	public void setTestObjectService(TestObjectService testObjectService) {
		this.testObjectService = testObjectService;
	}

	public DiseaseCategoryService getDiseaseCategoryService() {
		return diseaseCategoryService;
	}

	@Autowired
	public void setDiseaseCategoryService(
			DiseaseCategoryService diseaseCategoryService) {
		this.diseaseCategoryService = diseaseCategoryService;
	}

	public SysuserService getSysuserService() {
		return sysuserService;
	}

	@Autowired
	public void setSysuserService(SysuserService sysuserService) {
		this.sysuserService = sysuserService;
	}

	public DiseaseKeywordService getDiseaseKeywordService() {
		return diseaseKeywordService;
	}

	@Autowired
	public void setDiseaseKeywordService(
			DiseaseKeywordService diseaseKeywordService) {
		this.diseaseKeywordService = diseaseKeywordService;
	}

	public PatientService getPatientService() {
		return patientService;
	}

	@Autowired
	public void setPatientService(PatientService patientService) {
		this.patientService = patientService;
	}

	public SampleInfoService getSampleInfoService() {
		return sampleInfoService;
	}

	@Autowired
	public void setSampleInfoService(SampleInfoService sampleInfoService) {
		this.sampleInfoService = sampleInfoService;
	}

	public TestStatusService getTestStatusService() {
		return testStatusService;
	}

	@Autowired
	public void setTestStatusService(TestStatusService testStatusService) {
		this.testStatusService = testStatusService;
	}


	public RegistedService getRegistedService() {
		return registedService;
	}

	@Autowired
	public void setRegistedService(RegistedService registedService) {
		this.registedService = registedService;
	}
	

}
